import 'dart:convert';

class User {
  final String name;
  final String email;

  User(this.name, this.email);

  User.fromJson(Map<String, dynamic> json)
      : name = json['name'],
        email = json['email'];

  Map<String, dynamic> toJson() => <String, dynamic> {
    'name' : name,
    'email' : email,
  };
}

void main() {
  //一个JSON格式的用户列表字符串
  String jsonStr='[{"name":"Jack"},{"name":"Rose"}]';
  //将JSON字符串转为Dart对象(此处是List)
  List items = json.decode(jsonStr);
  jsonStr = '''
  {
    "name": "John Smith",
    "email": "john@example.com"
  }
  ''';
  Map<String, dynamic> userMap = json.decode(jsonStr);
  User user = User.fromJson(userMap);
  print('Howdy, ${user.name}!');
  print('We sent the verification link to ${user.email}.');
  var jsons = user.toJson();
  print(jsons);
  print(json.runtimeType);
  var jsonstr = json.encode(user);
  print(jsonstr);
  print(jsonstr.runtimeType);

}